import networkx as nx
import matplotlib.pyplot as plt
import random
import pulp
G = nx.DiGraph()

G.add_nodes_from(list(range(11)))
node_to_edge = {
    (0, 2): 0,
    (0, 1): 1,
    (2, 3): 2,
    (3, 4): 3,
    (1, 5): 4,
    (4, 6): 5,
    (4, 7): 6,
    (6, 5): 7,
    (5, 8): 8,
    (7, 9): 9,
    (8, 10): 10,
    (9, 10): 11
}
edge_to_node = {}
for k, v in node_to_edge.items():
    edge_to_node[v] = k
for k, _ in node_to_edge.items():
    u, v = k
    G.add_edge(u, v)
#nx.draw_networkx(G)
#plt.show()

c = [0,0,1,1,1,0,0,0,0,0,0,0]
prob = pulp.LpProblem("MultiObjective_ILP", pulp.LpMaximize)
# 定义变量
M = 2
x = pulp.LpVariable.dicts("x", range(12), lowBound=0, upBound=M, cat=pulp.LpInteger)
y = pulp.LpVariable.dicts("y", range(12), cat=pulp.LpBinary)
big_weight = 100  
small_weight = 1     
prob += big_weight * (x[10] + x[11]) - small_weight * pulp.lpSum([c[i] * y[i] for i in range(12)])
prob += x[0] == x[2]
prob += x[2] == x[3]
prob += sum(x[i] for i in [3]) == sum(x[i] for i in [5,6])
prob += x[1] == x[4]
prob += x[5] == x[7]
prob += x[4] + x[7] == x[8]
prob += x[8] == x[10]
prob += x[6] == x[9]
prob += x[9] == x[11]
prob += x[10] <= 1
prob += x[11] <= 1
for i in range(12):
    prob += x[i] <= M * y[i]

prob.solve(pulp.PULP_CBC_CMD())
prob.solve()

# 输出结果
print("Status:", pulp.LpStatus[prob.status])
print("Objective value =", pulp.value(prob.objective))

# 打印变量取值
for i in range(12):
    print(f"x{i} = {pulp.value(x[i])}, y{i} = {pulp.value(y[i])}")